import Vue from 'vue'
import Vuex from 'vuex'
//该插件用于持久化存储vuex中的数据
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:"",
    userInfo:{}
  },
  mutations: {
    updateToken(state,newToken){
       state.token=newToken
    },
    updateUserInfo(state,val){
      state.userInfo=val
    },
    updateUserPic(state,val){
      state.userInfo.user_pic=val
    }
  },
  getters:{
    username: (state)=>state.userInfo.username,
    nickname: (state)=>state.userInfo.nickname,
    user_pic: (state)=>state.userInfo.user_pic
  },
  actions: {
  },
  modules: {
  },
  //配置vuex插件
  plugins:[
    createPersistedState()
  ]
})
